﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Windows.Forms;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Nmo;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Trace;
namespace Entity
{
    public class KHOA
    {
        private String MAKHOA, TENKHOA;

        public String maKhoa
        {
            get { return MAKHOA; }
            set { MAKHOA = value; }
        }
        public String tenKhoa
        {
            get { return TENKHOA; }
            set { TENKHOA = value; }
        }
        /// <summary>
        /// 
        /// </summary>
        DataBaseAccess dataBaseAccess = new DataBaseAccess();

        public void hienthi_Khoa(DataGridView dtgKhoa)
        {
            try
            {
                DataTable dataTable = new DataTable();
                dataTable = dataBaseAccess.getDataTable("SELECT * FROM KHOA");
                dtgKhoa.DataSource = dataTable;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Loi hien thi datagridview " + ex.Message);
            }
        }

        public void them_Khoa(KHOA khoa)
        {
            String excuteString = "INSERT INTO KHOA VALUES('" + khoa.maKhoa + " ',' " 
                                                              + khoa.tenKhoa + "')";
            dataBaseAccess.excuteNonQuery(excuteString);
        }

        public void sua_Khoa(KHOA Khoa)
        {
            String excuteString = "UPDATE KHOA SET TENKHOA = '" + Khoa.tenKhoa + 
                                           "' WHERE MAKHOA = '" + Khoa.maKhoa + "'";
            dataBaseAccess.excuteNonQuery(excuteString);
        }

        public void xoa_Khoa(String makhoa)
        {
            String excuteString = " DELETE FROM KHOA WHERE MAKHOA = '" + makhoa + "'";
            dataBaseAccess.excuteNonQuery(excuteString);
        }
    }








}
